{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load market data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>交易日</th>\n",
       "      <th>合约代码</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>合约在交易所的代码</th>\n",
       "      <th>最新价</th>\n",
       "      <th>上次结算价</th>\n",
       "      <th>昨收盘</th>\n",
       "      <th>昨持仓量</th>\n",
       "      <th>今开盘</th>\n",
       "      <th>最高价</th>\n",
       "      <th>...</th>\n",
       "      <th>申买价四</th>\n",
       "      <th>申买量四</th>\n",
       "      <th>申卖价四</th>\n",
       "      <th>申卖量四</th>\n",
       "      <th>申买价五</th>\n",
       "      <th>申买量五</th>\n",
       "      <th>申卖价五</th>\n",
       "      <th>申卖量五</th>\n",
       "      <th>当日均价</th>\n",
       "      <th>业务日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>427</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.4032</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>429</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>430</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>432 rows × 44 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          交易日   合约代码  交易所代码  合约在交易所的代码     最新价   上次结算价     昨收盘   昨持仓量     今开盘  \\\n",
       "0    20180102  a1801    NaN        NaN  3035.0  3051.0  3035.0  26188  3035.0   \n",
       "1    20180102  a1801    NaN        NaN  3035.0  3051.0  3035.0  26188  3035.0   \n",
       "2    20180102  a1801    NaN        NaN  3035.0  3051.0  3035.0  26188  3035.0   \n",
       "3    20180102  a1801    NaN        NaN  3035.0  3051.0  3035.0  26188  3035.0   \n",
       "4    20180102  a1801    NaN        NaN  3035.0  3051.0  3035.0  26188  3035.0   \n",
       "..        ...    ...    ...        ...     ...     ...     ...    ...     ...   \n",
       "427  20180102  a1801    NaN        NaN  3049.0  3051.0  3035.0  26188  3035.0   \n",
       "428  20180102  a1801    NaN        NaN  3048.0  3051.0  3035.0  26188  3035.0   \n",
       "429  20180102  a1801    NaN        NaN  3048.0  3051.0  3035.0  26188  3035.0   \n",
       "430  20180102  a1801    NaN        NaN  3048.0  3051.0  3035.0  26188  3035.0   \n",
       "431  20180102  a1801    NaN        NaN  3048.0  3051.0  3035.0  26188  3035.0   \n",
       "\n",
       "        最高价  ...  申买价四  申买量四  申卖价四  申卖量四  申买价五  申买量五  申卖价五  申卖量五        当日均价  \\\n",
       "0    3035.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30350.0000   \n",
       "1    3035.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30350.0000   \n",
       "2    3035.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30350.0000   \n",
       "3    3035.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30350.0000   \n",
       "4    3035.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30350.0000   \n",
       "..      ...  ...   ...   ...   ...   ...   ...   ...   ...   ...         ...   \n",
       "427  3074.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30528.4032   \n",
       "428  3074.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30528.2751   \n",
       "429  3074.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30528.2751   \n",
       "430  3074.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30528.2751   \n",
       "431  3074.0  ...   0.0     0   0.0     0   0.0     0   0.0     0  30528.2751   \n",
       "\n",
       "         业务日期  \n",
       "0    20180102  \n",
       "1    20180102  \n",
       "2    20180102  \n",
       "3    20180102  \n",
       "4    20180102  \n",
       "..        ...  \n",
       "427  20180102  \n",
       "428  20180102  \n",
       "429  20180102  \n",
       "430  20180102  \n",
       "431  20180102  \n",
       "\n",
       "[432 rows x 44 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('a1801_20180102.csv', encoding='gb2312')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['交易日', '合约代码', '交易所代码', '合约在交易所的代码', '最新价', '上次结算价', '昨收盘', '昨持仓量',\n",
       "       '今开盘', '最高价', '最低价', '数量', '成交金额', '持仓量', '今收盘', '本次结算价', '涨停板价',\n",
       "       '跌停板价', '昨虚实度', '今虚实度', '最后修改时间', '最后修改毫秒', '申买价一', '申买量一', '申卖价一',\n",
       "       '申卖量一', '申买价二', '申买量二', '申卖价二', '申卖量二', '申买价三', '申买量三', '申卖价三', '申卖量三',\n",
       "       '申买价四', '申买量四', '申卖价四', '申卖量四', '申买价五', '申买量五', '申卖价五', '申卖量五', '当日均价',\n",
       "       '业务日期'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.columns = ['trade_date', 'symbol','exchange','symbol_in_exchange', 'last_price','prev_settle','prev_close','prev_open_interest',\n",
    "              'open','high','low','volume','turnover','open_interest','close','settle','limit_up',\n",
    "              'limit_down','prev_otm','otm','time','millisecond','bid_price1','bid_volume1','ask_price1','ask_volume1',\n",
    "              'bid_price2','bid_volume2','ask_price2','ask_volume2','bid_price3','bid_volume4','ask_price3','ask_volume3',\n",
    "              'bid_price4','bid_volume4','ask_price4','ask_volume4','bid_price5','bid_volume5','ask_price5','ask_volume5',\n",
    "              'avg_price','date'] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['avg_price2'] = df.turnover / df.volume"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>trade_date</th>\n",
       "      <th>symbol</th>\n",
       "      <th>exchange</th>\n",
       "      <th>symbol_in_exchange</th>\n",
       "      <th>last_price</th>\n",
       "      <th>prev_settle</th>\n",
       "      <th>prev_close</th>\n",
       "      <th>prev_open_interest</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>...</th>\n",
       "      <th>bid_volume4</th>\n",
       "      <th>ask_price4</th>\n",
       "      <th>ask_volume4</th>\n",
       "      <th>bid_price5</th>\n",
       "      <th>bid_volume5</th>\n",
       "      <th>ask_price5</th>\n",
       "      <th>ask_volume5</th>\n",
       "      <th>avg_price</th>\n",
       "      <th>date</th>\n",
       "      <th>avg_price2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>427</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.4032</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.403183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>429</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>430</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>432 rows × 45 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     trade_date symbol  exchange  symbol_in_exchange  last_price  prev_settle  \\\n",
       "0      20180102  a1801       NaN                 NaN      3035.0       3051.0   \n",
       "1      20180102  a1801       NaN                 NaN      3035.0       3051.0   \n",
       "2      20180102  a1801       NaN                 NaN      3035.0       3051.0   \n",
       "3      20180102  a1801       NaN                 NaN      3035.0       3051.0   \n",
       "4      20180102  a1801       NaN                 NaN      3035.0       3051.0   \n",
       "..          ...    ...       ...                 ...         ...          ...   \n",
       "427    20180102  a1801       NaN                 NaN      3049.0       3051.0   \n",
       "428    20180102  a1801       NaN                 NaN      3048.0       3051.0   \n",
       "429    20180102  a1801       NaN                 NaN      3048.0       3051.0   \n",
       "430    20180102  a1801       NaN                 NaN      3048.0       3051.0   \n",
       "431    20180102  a1801       NaN                 NaN      3048.0       3051.0   \n",
       "\n",
       "     prev_close  prev_open_interest    open    high  ...  bid_volume4  \\\n",
       "0        3035.0               26188  3035.0  3035.0  ...            0   \n",
       "1        3035.0               26188  3035.0  3035.0  ...            0   \n",
       "2        3035.0               26188  3035.0  3035.0  ...            0   \n",
       "3        3035.0               26188  3035.0  3035.0  ...            0   \n",
       "4        3035.0               26188  3035.0  3035.0  ...            0   \n",
       "..          ...                 ...     ...     ...  ...          ...   \n",
       "427      3035.0               26188  3035.0  3074.0  ...            0   \n",
       "428      3035.0               26188  3035.0  3074.0  ...            0   \n",
       "429      3035.0               26188  3035.0  3074.0  ...            0   \n",
       "430      3035.0               26188  3035.0  3074.0  ...            0   \n",
       "431      3035.0               26188  3035.0  3074.0  ...            0   \n",
       "\n",
       "     ask_price4  ask_volume4  bid_price5  bid_volume5  ask_price5  \\\n",
       "0           0.0            0         0.0            0         0.0   \n",
       "1           0.0            0         0.0            0         0.0   \n",
       "2           0.0            0         0.0            0         0.0   \n",
       "3           0.0            0         0.0            0         0.0   \n",
       "4           0.0            0         0.0            0         0.0   \n",
       "..          ...          ...         ...          ...         ...   \n",
       "427         0.0            0         0.0            0         0.0   \n",
       "428         0.0            0         0.0            0         0.0   \n",
       "429         0.0            0         0.0            0         0.0   \n",
       "430         0.0            0         0.0            0         0.0   \n",
       "431         0.0            0         0.0            0         0.0   \n",
       "\n",
       "     ask_volume5   avg_price      date    avg_price2  \n",
       "0              0  30350.0000  20180102  30350.000000  \n",
       "1              0  30350.0000  20180102  30350.000000  \n",
       "2              0  30350.0000  20180102  30350.000000  \n",
       "3              0  30350.0000  20180102  30350.000000  \n",
       "4              0  30350.0000  20180102  30350.000000  \n",
       "..           ...         ...       ...           ...  \n",
       "427            0  30528.4032  20180102  30528.403183  \n",
       "428            0  30528.2751  20180102  30528.275132  \n",
       "429            0  30528.2751  20180102  30528.275132  \n",
       "430            0  30528.2751  20180102  30528.275132  \n",
       "431            0  30528.2751  20180102  30528.275132  \n",
       "\n",
       "[432 rows x 45 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>trade_date</th>\n",
       "      <th>symbol</th>\n",
       "      <th>last_price</th>\n",
       "      <th>prev_settle</th>\n",
       "      <th>prev_close</th>\n",
       "      <th>prev_open_interest</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>...</th>\n",
       "      <th>limit_down</th>\n",
       "      <th>time</th>\n",
       "      <th>millisecond</th>\n",
       "      <th>bid_price1</th>\n",
       "      <th>bid_volume1</th>\n",
       "      <th>ask_price1</th>\n",
       "      <th>ask_volume1</th>\n",
       "      <th>avg_price</th>\n",
       "      <th>date</th>\n",
       "      <th>avg_price2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>08:59:00</td>\n",
       "      <td>289</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>498</td>\n",
       "      <td>3100.0</td>\n",
       "      <td>4</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>09:00:00</td>\n",
       "      <td>448</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>498</td>\n",
       "      <td>3098.0</td>\n",
       "      <td>21</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>09:00:19</td>\n",
       "      <td>616</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>498</td>\n",
       "      <td>3097.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>09:00:57</td>\n",
       "      <td>220</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>498</td>\n",
       "      <td>3080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>09:00:57</td>\n",
       "      <td>616</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>498</td>\n",
       "      <td>3079.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30350.0000</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30350.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>427</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>7540</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>14:59:19</td>\n",
       "      <td>134</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>53</td>\n",
       "      <td>3052.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30528.4032</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.403183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>7560</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>14:59:23</td>\n",
       "      <td>791</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>43</td>\n",
       "      <td>3052.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>429</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>7560</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>15:00:00</td>\n",
       "      <td>291</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>43</td>\n",
       "      <td>3052.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>430</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>7560</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>15:00:25</td>\n",
       "      <td>814</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>43</td>\n",
       "      <td>3052.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>431</th>\n",
       "      <td>20180102</td>\n",
       "      <td>a1801</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3051.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>26188</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>7560</td>\n",
       "      <td>...</td>\n",
       "      <td>2868.0</td>\n",
       "      <td>15:03:49</td>\n",
       "      <td>316</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>43</td>\n",
       "      <td>3052.0</td>\n",
       "      <td>1</td>\n",
       "      <td>30528.2751</td>\n",
       "      <td>20180102</td>\n",
       "      <td>30528.275132</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>432 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     trade_date symbol  last_price  prev_settle  prev_close  \\\n",
       "0      20180102  a1801      3035.0       3051.0      3035.0   \n",
       "1      20180102  a1801      3035.0       3051.0      3035.0   \n",
       "2      20180102  a1801      3035.0       3051.0      3035.0   \n",
       "3      20180102  a1801      3035.0       3051.0      3035.0   \n",
       "4      20180102  a1801      3035.0       3051.0      3035.0   \n",
       "..          ...    ...         ...          ...         ...   \n",
       "427    20180102  a1801      3049.0       3051.0      3035.0   \n",
       "428    20180102  a1801      3048.0       3051.0      3035.0   \n",
       "429    20180102  a1801      3048.0       3051.0      3035.0   \n",
       "430    20180102  a1801      3048.0       3051.0      3035.0   \n",
       "431    20180102  a1801      3048.0       3051.0      3035.0   \n",
       "\n",
       "     prev_open_interest    open    high     low  volume  ...  limit_down  \\\n",
       "0                 26188  3035.0  3035.0  3035.0       4  ...      2868.0   \n",
       "1                 26188  3035.0  3035.0  3035.0       4  ...      2868.0   \n",
       "2                 26188  3035.0  3035.0  3035.0       4  ...      2868.0   \n",
       "3                 26188  3035.0  3035.0  3035.0       4  ...      2868.0   \n",
       "4                 26188  3035.0  3035.0  3035.0       4  ...      2868.0   \n",
       "..                  ...     ...     ...     ...     ...  ...         ...   \n",
       "427               26188  3035.0  3074.0  3035.0    7540  ...      2868.0   \n",
       "428               26188  3035.0  3074.0  3035.0    7560  ...      2868.0   \n",
       "429               26188  3035.0  3074.0  3035.0    7560  ...      2868.0   \n",
       "430               26188  3035.0  3074.0  3035.0    7560  ...      2868.0   \n",
       "431               26188  3035.0  3074.0  3035.0    7560  ...      2868.0   \n",
       "\n",
       "         time  millisecond  bid_price1 bid_volume1  ask_price1  ask_volume1  \\\n",
       "0    08:59:00          289      3035.0         498      3100.0            4   \n",
       "1    09:00:00          448      3035.0         498      3098.0           21   \n",
       "2    09:00:19          616      3035.0         498      3097.0            1   \n",
       "3    09:00:57          220      3035.0         498      3080.0            1   \n",
       "4    09:00:57          616      3035.0         498      3079.0            1   \n",
       "..        ...          ...         ...         ...         ...          ...   \n",
       "427  14:59:19          134      3048.0          53      3052.0            1   \n",
       "428  14:59:23          791      3048.0          43      3052.0            1   \n",
       "429  15:00:00          291      3048.0          43      3052.0            1   \n",
       "430  15:00:25          814      3048.0          43      3052.0            1   \n",
       "431  15:03:49          316      3048.0          43      3052.0            1   \n",
       "\n",
       "      avg_price      date    avg_price2  \n",
       "0    30350.0000  20180102  30350.000000  \n",
       "1    30350.0000  20180102  30350.000000  \n",
       "2    30350.0000  20180102  30350.000000  \n",
       "3    30350.0000  20180102  30350.000000  \n",
       "4    30350.0000  20180102  30350.000000  \n",
       "..          ...       ...           ...  \n",
       "427  30528.4032  20180102  30528.403183  \n",
       "428  30528.2751  20180102  30528.275132  \n",
       "429  30528.2751  20180102  30528.275132  \n",
       "430  30528.2751  20180102  30528.275132  \n",
       "431  30528.2751  20180102  30528.275132  \n",
       "\n",
       "[432 rows x 23 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "COLS_TO_DROP = ['exchange','symbol_in_exchange', 'bid_price2','bid_volume2','ask_price2','ask_volume2',\n",
    "                'bid_price3','bid_volume4','ask_price3','ask_volume3','bid_price4','bid_volume4',\n",
    "                'ask_price4','ask_volume4','bid_price5','bid_volume5','ask_price5','ask_volume5',\n",
    "                'prev_otm','otm', 'close', 'settle']\n",
    "df = df.drop(COLS_TO_DROP, axis=1)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Homework\n",
    "Write a function tick2min to transform tick data to minute data\n",
    "Hint:\n",
    "1. Market open and close time - better to write a function(raw2tick) to handle different assets\n",
    "2. Morning break and reopen? another function: get_trade_datetime\n",
    "3. What if no trade at the end of minute? pandas.ffill"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "symbol_trade_time = {}\n",
    "symbol_trade_list = []\n",
    "\n",
    "\n",
    "def build_trade_time():\n",
    "    ### \"trade time reference \"\n",
    "    ### from http://qhsxf.com/%E6%9C%9F%E8%B4%A7%E4%BA%A4%E6%98%93%E6%97%B6%E9%97%B4.html\n",
    "    ### from http://www.fcqihuo.com/ncqh/uploads/a/futuresAnswer/2020/0828/16802.html\n",
    "\n",
    "    # 没有夜盘\n",
    "    trade_time_0 = {\"night_trade_start_datetime\":\"09:00:00\", \n",
    "                    \"night_trade_end_datetime\":\"09:00:00\", \n",
    "                    \"morning_trade_start_datetime\":\"09:00:00\",\n",
    "                    \"morning_break_start_datetime\":\"10:15:00\", \n",
    "                    \"morning_break_end_datetime\":\"10:30:00\", \n",
    "                    \"morning_trade_end_datetime\":\"11:30:00\",\n",
    "                    \"afternoon_trade_start_datetime\":\"13:30:00\", \n",
    "                    \"afternoon_trade_end_datetime\":\"15:00:00\"}\n",
    "\n",
    "    # 夜盘为 21：00：00 到 23：00：00\n",
    "    trade_time_1 = {\"night_trade_start_datetime\":\"21:00:00\", \n",
    "                    \"night_trade_end_datetime\":\"23:00:00\", \n",
    "                    \"morning_trade_start_datetime\":\"09:00:00\",\n",
    "                    \"morning_break_start_datetime\":\"10:15:00\", \n",
    "                    \"morning_break_end_datetime\":\"10:30:00\", \n",
    "                    \"morning_trade_end_datetime\":\"11:30:00\",\n",
    "                    \"afternoon_trade_start_datetime\":\"13:30:00\", \n",
    "                    \"afternoon_trade_end_datetime\":\"15:00:00\"}\n",
    "\n",
    "    # 夜盘为 21：00：00 到 1：00：00\n",
    "    trade_time_2 = {\"night_trade_start_datetime\":\"21:00:00\", \n",
    "                    \"night_trade_end_datetime\":\"1:00:00\", \n",
    "                    \"morning_trade_start_datetime\":\"09:00:00\",\n",
    "                    \"morning_break_start_datetime\":\"10:15:00\", \n",
    "                    \"morning_break_end_datetime\":\"10:30:00\", \n",
    "                    \"morning_trade_end_datetime\":\"11:30:00\",\n",
    "                    \"afternoon_trade_start_datetime\":\"13:30:00\", \n",
    "                    \"afternoon_trade_end_datetime\":\"15:00:00\"}\n",
    "\n",
    "    # 夜盘为 21：00：00 到 2：30：00\n",
    "    trade_time_3 = {\"night_trade_start_datetime\":\"21:00:00\", \n",
    "                    \"night_trade_end_datetime\":\"2:30:00\", \n",
    "                    \"morning_trade_start_datetime\":\"09:00:00\",\n",
    "                    \"morning_break_start_datetime\":\"10:15:00\", \n",
    "                    \"morning_break_end_datetime\":\"10:30:00\", \n",
    "                    \"morning_trade_end_datetime\":\"11:30:00\",\n",
    "                    \"afternoon_trade_start_datetime\":\"13:30:00\", \n",
    "                    \"afternoon_trade_end_datetime\":\"15:00:00\"}\n",
    "\n",
    "    # 夜盘无，没有breaktime 早盘 9:30-11:30  下午盘 13:00 - 15:00\n",
    "    trade_time_4 = {\"night_trade_start_datetime\":\"09:00:00\", \n",
    "                    \"night_trade_end_datetime\":\"09:00:00\", \n",
    "                    \"morning_trade_start_datetime\":\"09:30:00\",\n",
    "                    \"morning_break_start_datetime\":\"10:00:00\", \n",
    "                    \"morning_break_end_datetime\":\"10:00:00\", \n",
    "                    \"morning_trade_end_datetime\":\"11:30:00\",\n",
    "                    \"afternoon_trade_start_datetime\":\"13:00:00\", \n",
    "                    \"afternoon_trade_end_datetime\":\"15:00:00\"}\n",
    "\n",
    "     # 夜盘无，没有breaktime 早盘 9:15-11:30  下午盘 13:00 - 15:15\n",
    "    trade_time_5 = {\"night_trade_start_datetime\":\"09:00:00\", \n",
    "                    \"night_trade_end_datetime\":\"09:00:00\", \n",
    "                    \"morning_trade_start_datetime\":\"09:15:00\",\n",
    "                    \"morning_break_start_datetime\":\"10:00:00\", \n",
    "                    \"morning_break_end_datetime\":\"10:00:00\", \n",
    "                    \"morning_trade_end_datetime\":\"11:30:00\",\n",
    "                    \"afternoon_trade_start_datetime\":\"13:00:00\", \n",
    "                    \"afternoon_trade_end_datetime\":\"15:15:00\"}\n",
    "    \n",
    "    SymbolInTradeTime0 = [\"SM\",\"SF\",\"WH\",\"JR\",\"LR\",\"PM\",\"RI\",\"RS\",\"UR\",\"CJ\",\"AP\",\\\n",
    "                          \"bb\",\"fb\",\"lh\",\"jd\",\\\n",
    "                          \"wr\",\\\n",
    "                          ]\n",
    "    for symbol in SymbolInTradeTime0:\n",
    "        symbol_trade_time[symbol] = trade_time_0\n",
    "\n",
    "\n",
    "    SymbolInTradeTime1 = [\"FG\",\"SA\",\"MA\",\"SR\",\"TA\",\"RM\",\"OI\",\"CF\",\"CY\",\"PF\",\"ZC\",\\\n",
    "                           \"i\",\"j\",\"jm\",\"a\",\"b\",\"m\",\"p\",\"y\",\"c\",\"cs\",\"pp\",\"v\",\"eb\",\"eg\",\"pg\",\"rr\",\"l\",\\\n",
    "                           \"fu\",\"ru\",\"bu\",\"sp\",\"rb\",\"hc\",\\\n",
    "                           \"lu\",\"nr\"]\n",
    "    for symbol in SymbolInTradeTime1:\n",
    "        symbol_trade_time[symbol] = trade_time_1\n",
    "\n",
    "\n",
    "    SymbolInTradeTime2 = [\"cu\",\"pb\",\"al\",\"zn\",\"sn\",\"ni\",\"ss\",\\\n",
    "                          \"bc\"]\n",
    "    for symbol in SymbolInTradeTime2:\n",
    "        symbol_trade_time[symbol] = trade_time_2\n",
    "\n",
    "    \n",
    "    SymbolInTradeTime3 = [\"cu\",\"pb\",\"al\",\"zn\",\"sn\",\"ni\",\"ss\",\"au\",\"ag\",\\\n",
    "                          \"sc\",]\n",
    "    for symbol in SymbolInTradeTime3:\n",
    "        symbol_trade_time[symbol] = trade_time_3\n",
    "\n",
    "    SymbolInTradeTime4 = [\"IF\",\"IC\",\"IH\"]\n",
    "    for symbol in SymbolInTradeTime4:\n",
    "        symbol_trade_time[symbol] = trade_time_4\n",
    "   \n",
    "    SymbolInTradeTime5 = [\"T\",\"TF\",\"TS\"]\n",
    "    for symbol in SymbolInTradeTime5:\n",
    "        symbol_trade_time[symbol] = trade_time_5\n",
    "\n",
    "    return None\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def raw2tick(df, symbol='IH'):\n",
    "    \"\"\"\n",
    "    Input: a raw DataFrame downloaded from DataVendor\n",
    "    Returns: a DataFrame with data only in market open time\n",
    "    \"\"\"\n",
    "    # Code begins\n",
    "    \n",
    "    night_trade_start_datetime, night_trade_end_datetime, morning_trade_start_datetime,morning_break_start_datetime, \\\n",
    "    morning_break_end_datetime, morning_trade_end_datetime,afternoon_trade_start_datetime, afternoon_trade_end_datetime = get_trade_time(symbol)\n",
    "    \n",
    "    if(night_trade_start_datetime<=night_trade_end_datetime):\n",
    "        df = df.loc[ ((df.time > night_trade_start_datetime) & (df.time < night_trade_end_datetime)) |\\\n",
    "                     ((df.time > morning_trade_start_datetime) & (df.time < morning_break_start_datetime)) |\\\n",
    "                     ((df.time > morning_break_end_datetime) & (df.time < morning_trade_end_datetime)) |\\\n",
    "                     ((df.time > afternoon_trade_start_datetime) & (df.time < afternoon_trade_end_datetime)) |\\\n",
    "                     ((df.time == night_trade_end_datetime) & (df.millisecond == 0)) |\\\n",
    "                     ((df.time == morning_break_start_datetime) & (df.millisecond == 0)) |\\\n",
    "                     ((df.time == morning_trade_end_datetime) & (df.millisecond == 0)) |\\\n",
    "                     ((df.time == afternoon_trade_end_datetime) & (df.millisecond == 0)) ]\n",
    "    else: #cross '00:00:00'\n",
    "        df = df.loc[ ((df.time > night_trade_start_datetime) & (df.time <= '23:59:59')) |\\\n",
    "                     ((df.time > '00:00:00') & (df.time < night_trade_end_datetime)) |\\\n",
    "                     ((df.time > morning_trade_start_datetime) & (df.time < morning_break_start_datetime)) |\\\n",
    "                     ((df.time > morning_break_end_datetime) & (df.time < morning_trade_end_datetime)) |\\\n",
    "                     ((df.time > afternoon_trade_start_datetime) & (df.time < afternoon_trade_end_datetime)) |\\\n",
    "                     ((df.time == night_trade_end_datetime) & (df.millisecond == 0)) |\\\n",
    "                     ((df.time == morning_break_start_datetime) & (df.millisecond == 0)) |\\\n",
    "                     ((df.time == morning_trade_end_datetime) & (df.millisecond == 0)) |\\\n",
    "                     ((df.time == afternoon_trade_end_datetime) & (df.millisecond == 0)) ]\n",
    "\n",
    "    \n",
    "    \n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "NIGHT_ABNORMAL_DATES = []\n",
    "def get_trade_time(symbol):\n",
    "    \"\"\" \n",
    "    Return trade datettime includes: night/day open, close datetime\n",
    "    if no break in morning, moring break start/end datetime would be set as monring_trade_end_time\n",
    "    \"\"\"\n",
    "    trade_date = \"1.1\"\n",
    "    if trade_date in NIGHT_ABNORMAL_DATES:\n",
    "        return None\n",
    "\n",
    "    if symbol not in list(symbol_trade_time.keys()):\n",
    "        return None\n",
    "    \n",
    "    #return (night_trade_start_datetime, night_trade_end_datetime, morning_trade_start_datetime,\n",
    "    #morning_break_start_datetime, morning_break_end_datetime, morning_trade_end_datetime,\n",
    "    #afternoon_trade_start_datetime, afternoon_trade_end_datetime)\n",
    "    return list(symbol_trade_time[symbol].values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def tick2min(df):\n",
    "    \"\"\"\n",
    "    Input: a raw DataFrame of market tick data\n",
    "    Returns: a DataFrame with Open High Low Close price sampled by 1 minute\n",
    "    resample\n",
    "    Note:\n",
    "    1. minute begins: 09:01:00,000, should be included in first minute\n",
    "    \n",
    "    \"\"\"\n",
    "    # Code begins\n",
    "    \n",
    "    df['candle_begin_time_GMT8'] = pd.to_datetime(df['time'])\n",
    "    df = df.set_index('candle_begin_time_GMT8')\n",
    "    df_ohlc = (df['last_price'].resample(\n",
    "        \"1min\", label='right', closed='right').ohlc())\n",
    "    \n",
    "    df_ohlc  = df_ohlc.fillna(method='ffill')\n",
    "\n",
    "    df_vol_turnover = df[['volume', 'turnover']].diff()\n",
    "    df_vol_turnover = df_vol_turnover.fillna(0)\n",
    "\n",
    "    df_vol_turnover = (df_vol_turnover.resample(\n",
    "        \"1min\", label='right', closed='right').sum())\n",
    "\n",
    "\n",
    "    df_date_time = (df[['trade_date', 'time']].resample(\n",
    "        \"1min\", label='right', closed='right').last())\n",
    "\n",
    "    df_date_time  = df_date_time.fillna(method='ffill')\n",
    "\n",
    "    dfdata = df_ohlc.merge(df_vol_turnover, left_index=True, right_index=True)\n",
    "    dfdata = dfdata.merge(df_date_time,left_index=True, right_index=True)\n",
    "\n",
    "\n",
    "    \n",
    "    return dfdata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "build_trade_time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "dfdata = raw2tick(df,\"a\") #豆类1号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-11-7a04d6274638>:12: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  df['candle_begin_time_GMT8'] = pd.to_datetime(df['time'])\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>turnover</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>candle_begin_time_GMT8</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-01-16 09:01:00</th>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>09:00:57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 09:02:00</th>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>983640.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>09:01:57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 09:03:00</th>\n",
       "      <td>3074.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>09:02:10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 09:04:00</th>\n",
       "      <td>3074.0</td>\n",
       "      <td>3074.0</td>\n",
       "      <td>3046.0</td>\n",
       "      <td>3046.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>121840.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>09:03:59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 09:05:00</th>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>3035.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>6070000.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>09:04:45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 14:56:00</th>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>792740.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>14:55:54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 14:57:00</th>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>14:56:52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 14:58:00</th>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>304900.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>14:57:42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 14:59:00</th>\n",
       "      <td>3049.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>1890180.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>14:58:59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-16 15:00:00</th>\n",
       "      <td>3048.0</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>3048.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1219400.0</td>\n",
       "      <td>20180102.0</td>\n",
       "      <td>14:59:23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>360 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                          open    high     low   close  volume   turnover  \\\n",
       "candle_begin_time_GMT8                                                      \n",
       "2021-01-16 09:01:00     3035.0  3035.0  3035.0  3035.0     0.0        0.0   \n",
       "2021-01-16 09:02:00     3035.0  3074.0  3035.0  3074.0    32.0   983640.0   \n",
       "2021-01-16 09:03:00     3074.0  3074.0  3074.0  3074.0     0.0        0.0   \n",
       "2021-01-16 09:04:00     3074.0  3074.0  3046.0  3046.0     4.0   121840.0   \n",
       "2021-01-16 09:05:00     3035.0  3035.0  3035.0  3035.0   200.0  6070000.0   \n",
       "...                        ...     ...     ...     ...     ...        ...   \n",
       "2021-01-16 14:56:00     3049.0  3049.0  3049.0  3049.0    26.0   792740.0   \n",
       "2021-01-16 14:57:00     3049.0  3049.0  3049.0  3049.0     0.0        0.0   \n",
       "2021-01-16 14:58:00     3049.0  3049.0  3049.0  3049.0    10.0   304900.0   \n",
       "2021-01-16 14:59:00     3049.0  3049.0  3048.0  3048.0    62.0  1890180.0   \n",
       "2021-01-16 15:00:00     3048.0  3049.0  3048.0  3048.0    40.0  1219400.0   \n",
       "\n",
       "                        trade_date      time  \n",
       "candle_begin_time_GMT8                        \n",
       "2021-01-16 09:01:00     20180102.0  09:00:57  \n",
       "2021-01-16 09:02:00     20180102.0  09:01:57  \n",
       "2021-01-16 09:03:00     20180102.0  09:02:10  \n",
       "2021-01-16 09:04:00     20180102.0  09:03:59  \n",
       "2021-01-16 09:05:00     20180102.0  09:04:45  \n",
       "...                            ...       ...  \n",
       "2021-01-16 14:56:00     20180102.0  14:55:54  \n",
       "2021-01-16 14:57:00     20180102.0  14:56:52  \n",
       "2021-01-16 14:58:00     20180102.0  14:57:42  \n",
       "2021-01-16 14:59:00     20180102.0  14:58:59  \n",
       "2021-01-16 15:00:00     20180102.0  14:59:23  \n",
       "\n",
       "[360 rows x 8 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfout = tick2min(dfdata)\n",
    "dfout"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So you can write your own pipeline to handle all kinds of market data from now"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1596: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  self.obj[key] = _infer_fill_value(value)\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1745: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  isetter(ilocs[0], value)\n"
     ]
    }
   ],
   "source": [
    "df.loc[:,('candle_begin_time_GMT8')] = pd.to_datetime(df['time'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[:,('candle_begin_time_GMT8')] = pd.to_datetime(df['time'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.loc[:,('time')] =  pd.to_datetime(df['time'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
